import axios from "@/utils/request";
import {Invite, Report, RequestParams} from "@/model/home/answer";

//获取所有问题
export function getList(current: number, size: number) {
    return axios({
        url: `/answer/problem/web/getList/${current}/${size}`,
        method: "get"
    })
}

//用户点赞问题
export function like(giveALike: object) {
    return axios({
        url: "/answer/giveALike/web/like",
        method: "post",
        data: giveALike
    })
}

//从关联表获取当前用户点赞的数据
export function getUserGiveALikeListById(userId: number) {
    return axios({
        url: "/answer/giveALike/web/getUserGiveALikeListById/" + userId,
        method: "get",
    })
}

//上传问题
export function upload(uploadProblem: object) {
    return axios({
        url: "/answer/problem/web/upload",
        method: "post",
        data: uploadProblem
    })
}

//根据问题id获取问题信息(作者)
export function getProblemById(id: number) {
    return axios({
        url: "/answer/problem/web/" + id,
        method: "get"
    })
}

//根据id获取用户信息
export function getUserinfoById(id: number) {
    return axios({
        url: "/user/user/web/" + id,
        method: "get"
    })
}

//问题的回复
export function handleReply(reply: object) {
    return axios({
        url: "/answer/reply/web/reply",
        method: "post",
        data: reply
    })
}

//获取当前问题的一级评论
export function getLevel1Comments(problemId: number) {
    return axios({
        url: "/answer/reply/web/getLevel1Comments/" + problemId,
        method: "get"
    })
}

//问题回复点赞
export function likeReply(replyGiveALike: object) {
    return axios({
        url: "/answer/replyGiveALike/web/likeReply",
        method: "post",
        data: replyGiveALike
    })
}

//根据问题id和用户id查询用户点赞信息
export function selectReplyGiveALive(problemId: number, userId: number) {
    return axios({
        url: `/answer/replyGiveALike/web/selectReplyGiveALive/${problemId}/${userId}`,
        method: "get"
    })
}

//删除图片
export function deleteImg(imgArr: Array<string>) {
    return axios({
        url: "/thirdParty/oss/deleteImg",
        method: "delete",
        data: imgArr
    })
}

//问题回复置顶
export function replyTop(problemId: number, replyId: number) {
    return axios({
        url: `/answer/reply/web/replyTop/${problemId}/${replyId}`,
        method: "put"
    })
}

//热评
export function hopReply() {
    return axios({
        url: '/answer/reply/web/hopReply',
        method: "get"
    })
}

//二级回复
export function secondReply(secondReply: object) {
    return axios({
        url: '/answer/secondReply/web/secondReply',
        method: "post",
        data: secondReply
    })
}

//根据问题id获取一级和二级回复
export function getFirstAndSecondReply(problemId: number) {
    return axios({
        url: '/answer/secondReply/web/getFirstAndSecondReply/' + problemId,
        method: "get"
    })
}

//保存用户浏览问题记录
export function saveUserBrowse(browse: object) {
    return axios({
        url: '/answer/browse/web/saveUserBrowse',
        method: "post",
        data: browse
    })
}

//根据点赞数查询前十条问题
export function rankBeforeTenToGoodProblem() {
    return axios({
        url: '/answer/problem/web/rankBeforeTen',
        method: "get"
    })
}

//根据用户回答数查询前十个用户
export function rankBeforeTenToReplyCount() {
    return axios({
        url: '/user/user/web/rankBeforeTen',
        method: "get"
    })
}

//全文检索
export function searchProblem(requestParams: RequestParams) {
    return axios({
        url: '/es/web/searchProblem',
        method: "post",
        data: requestParams
    })
}

//自动补全
export function getSuggestion(key: string) {
    return axios({
        url: '/es/web/problem/suggestion/' + key,
        method: "get"
    })
}

//获取当前用户关注的人发表的问题
export function getUserAttentionPublishProblem(userId: number) {
    return axios({
        url: '/makeFriend/attention/web/getUserAttentionPublishProblem/' + userId,
        method: "get"
    })
}

//获取推荐邀请列表
export function getRecommendList(userId: number) {
    return axios({
        url: '/makeFriend/invite/web/getRecommendList/' + userId,
        method: "get"
    })
}

//邀请用户回答问题
export function inviteUser(invite: Invite) {
    return axios({
        url: '/makeFriend/invite/web/inviteUser',
        method: "post",
        data: invite
    })
}

//用户举报问题
export function reportProblem(report: Report) {
    return axios({
        url: '/answer/report/web/reportProblem',
        method: "post",
        data: report
    })
}

//根据用户id查询用户是否举报了当前这个问题
export function getUserIsReportProblem(userId: number, problemId: number) {
    return axios({
        url: `/answer/report/web/getUserIsReportProblem/${userId}/${problemId}`,
        method: "get"
    })
}